﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace BizCollegeWebApp.Models
{
    [System.ComponentModel.DataAnnotations.MetadataType(typeof(Course.CourseMetadata))]
    public partial class Course
    {
        public int GetFirstContentId()
        {
            List<int> ids = CourseContents.Select(c => c.ContentID).ToList();
            if (ids.Any())
            {
                ids.Sort();
                return ids[0];
            }
            return -1;
        }

        public int GetNextContentId(int currentId)
        {
            List<int> ids = CourseContents.Select(c => c.ContentID).ToList();
            if (ids.Any())
            {
                ids.Sort();
                int idx = ids.IndexOf(currentId);
                if (idx == ids.Count - 1)
                {
                    return -1;
                }
                else
                {
                    return ids[idx + 1];
                }
            }
            return -1;
        }

        private class CourseMetadata
        {
            [Required]
            public string CourseName;

            [Required]
            public string CourseDesciption;

        }
    }
}